package com.rocky.component.util.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.rocky.component.util.constant.Formatter;

import java.io.IOException;
import java.time.LocalDate;

/**
 * @author rocky
 * date 2025-08-09
 * Description:
 */
public class DateSerializer extends JsonSerializer<LocalDate> {
    @Override
    public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        String formatValue;
        if (value == null) {
            formatValue = null;
        }else {
            formatValue = value.format(Formatter.DATE_FORMATTER);
        }
        gen.writeString(formatValue);
    }
}
